package com.ywl.task.service.impl;

import com.ywl.task.mapper.TaskMapper;
import com.ywl.task.pojo.Task;
import com.ywl.task.service.TaskService;
import com.ywl.task.util.pojo.QdResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author 严伟伦
 * @Company 无
 * @Description
 * @Date: 2024/9/10 11:21
 */
@Service
public class TaskServiceImpl implements TaskService {

    @Autowired
    private TaskMapper taskMapper;
    @Override
    public QdResult selectList(Task task,String projectId, Long parentId) {

        return QdResult.success(taskMapper.selectList(task,projectId,parentId));
    }


    @Override
    public QdResult selectListByUserId(Long userId) {

        return QdResult.success(taskMapper.selectListByUserId(userId));
    }

    @Override
    public QdResult addTask(Task task) {

        if (task.getStartTime().after(task.getEndTime())){
            return QdResult.error(500,"时间异常");
        }
        if (taskMapper.selectTaskById(task.getTaskId()) != null){
            return QdResult.error(500,"重复");
        }
        if (taskMapper.addTask(task) == 1){
            return QdResult.success();
        }
        return QdResult.error();
    }

    @Override
    public QdResult updateTaskParentById(Long taskId) {
        return QdResult.success(taskMapper.updateTaskParentById(taskId));
    }

    @Override
    public QdResult updateTask(Task task) {
        if (task == null){
            return QdResult.error();
        }
        if (taskMapper.updateTask(task) == 1){
            return QdResult.success();
        }
        return QdResult.error();
    }

    @Override
    public QdResult updateTaskStatusById(Long taskId) {
        if (taskMapper.updateTaskStatusById(taskId) == 1){
            return QdResult.success();
        }
        return QdResult.error();
    }

    @Override
    public QdResult updateTaskStatusByIds(Long[] taskIds) {
        return QdResult.success(200,"ok",taskMapper.updateTaskStatusByIds(taskIds,99));
    }
}
